﻿using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PT.Common;

namespace PT.Timing.Tests {
    /// <summary>
    ///This is a test class for MetronomeTest and is intended
    ///to contain all Metronome Unit Tests
    ///</summary>
    [TestClass]
    public class MetronomeTest {

        /// <summary> A test for BarDuration.</summary>
        [TestMethod]
        public void BarDurationTest1() {
            var target = new Metronome {
                Tempo = 60,
                TimeSignature = new Rational(3, 4)
            };
            long expectedBarDuration = 3 * Stopwatch.Frequency;
            long actual = target.BarDuration;

            var acceptableError = Stopwatch.Frequency / 10000;

            Assert.IsTrue(
                expectedBarDuration - acceptableError < actual &&
                actual < expectedBarDuration + acceptableError
            );
        }

        /// <summary> A test for BarDuration.</summary>
        [TestMethod]
        public void BarDurationTest2() {
            var target = new Metronome {
                Tempo = 120,
                TimeSignature = new Rational(5, 4)
            };
            long expectedBarDuration = 5 * Stopwatch.Frequency / 2;
            long actual = target.BarDuration;

            var acceptableError = Stopwatch.Frequency / 10000;

            Assert.IsTrue(
                expectedBarDuration - acceptableError < actual &&
                actual < expectedBarDuration + acceptableError
            );
        }
    }
}
